package com.hackerrank.challenges.similarpair;

import java.util.Scanner;

public class Solution {
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt(), T = in.nextInt(), p[] = new int[n + 1], nsp = 0;
		for(int i = 1; i < n; i++) {
			int s = in.nextInt(), e = in.nextInt();
			p[e] = s;
		}
		for(int i = 1; i <= n; i++) {
			int B = i, A = p[B];
			while(A > 0) {
				if(Math.abs(A - B) <= T)
					nsp++;
				A = p[A];
			}
		}
		System.out.println(nsp);
	}
}
